package cn.lzm.basic.listener;

import cn.lzm.system.service.IPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener // 表示自定义监听器需要被spring管理
@Slf4j
public class PermissionScanInitInstener implements ServletContextListener {
    @Autowired
    private IPermissionService permissionService;
    // Spring 容器初始化之后被调用

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 防止我们代码比较复杂影响项目启动速度 我们创建线程来运行
        new Thread(new Runnable() {
            @Override
            public void run() {
                log.info("contextInitialized start...");
                // 执行permission数据添加方法
                permissionService.scanPermission();
                log.info("contextInitialized stop...");
            }
        }).start();
    }
}
